import { defHttp } from '/@/utils/http/axios';
import { useMessage } from "/@/hooks/web/useMessage";

const { createConfirm } = useMessage();

enum Api {
  list = '/camelliaDeviceReport/camelliaDeviceReport/list',
  save='/camelliaDeviceReport/camelliaDeviceReport/add',
  edit='/camelliaDeviceReport/camelliaDeviceReport/edit',
  deleteOne = '/camelliaDeviceReport/camelliaDeviceReport/delete',
  deleteBatch = '/camelliaDeviceReport/camelliaDeviceReport/deleteBatch',
  importExcel = '/camelliaDeviceReport/camelliaDeviceReport/importExcel',
  exportXls = '/camelliaDeviceReport/camelliaDeviceReport/exportXls',
  selRoles='/camelliaDevicePatrol/camelliaDevicePatrol/selList',
  repairSave='/camelliaDeviceRepairs/camelliaDeviceRepair/add', 
  repairRelationSave='/camelliaDeviceRepairRelationshiop/camelliaDeviceRepairRelationshiop/add',//添加 维修关系表
}

/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;

/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;

/**
 * 列表接口
 * @param params
 */
export const list = (params) => defHttp.get({ url: Api.list, params });


//获取角色列表信息
export const selRole = (params) => defHttp.get({ url: Api.selRoles, params });

/**
 * 删除单个
 * @param params
 * @param handleSuccess
 */
export const deleteOne = (params,handleSuccess) => {
  return defHttp.delete({url: Api.deleteOne, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}

 /**
  * 查询维修人员
  */
 export const selTest = (params) => defHttp.get({ url: Api.selRoles, params });
 //修改报修状态
 export const reportEdit = (params) => defHttp.post({ url: Api.edit, params });

 //添加维修订单
 export const repairSave = (params) => defHttp.post({ url: Api.repairSave, params });
 
 //添加维修关系
 export const repairRelationSave = (params) => defHttp.post({ url: Api.repairRelationSave, params });
 

/**
 * 批量删除
 * @param params
 * @param handleSuccess
 */
export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.deleteBatch, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}

/**
 * 保存或者更新
 * @param params
 * @param isUpdate
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({ url: url, params }, { isTransformResponse: false });
}
